PostgreSQL查询表名称及表结构
1. 查询表名称
在psql状态下查询表名称
\dt
SQL方式查看表名称
SELECT viewname FROM pg_views WHERE schemaname ='public'
PostgreSQL获取数据库中所有view名 视图
SELECT viewname FROM pg_views WHERE schemaname ='public'
2. 查询表结构
在psql状态下查询表结构
SQL方式查看表结构
SELECT a.attnum,
a.attname AS field,
t.typname AS type,
a.attlen AS length,
a.atttypmod AS lengthvar,
a.attnotnull AS notnull,
b.description AS comment
FROM pg_class c,
pg_attribute a
LEFT OUTER JOIN pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid,
pg_type t
WHERE c.relname = 'udoc_saldiscount'
and a.attnum > 0
and a.attrelid = c.oid
and a.atttypid = t.oid
ORDER BY a.attnum;